package com.pingan.glue.gluegame.common.aspect;

import com.pingan.glue.gluegame.exception.BusinessException;
import com.pingan.glue.gluegame.response.ResponseResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class GlobalExceptionAdvice {
    private static final Logger LOGGER = LoggerFactory.getLogger(GlobalExceptionAdvice.class);

    @ResponseBody
    @ExceptionHandler(value= BusinessException.class)
    public ResponseResult errorHandler(BusinessException ex){
        LOGGER.error("GlobalExceptionAdvice_errorHandler_error:",ex);
        return new ResponseResult(ex.getCode(),ex.getMessage());
    }
}
